using System.Collections;
using UnityEngine;

public class PouringPrecisionController : MonoBehaviour
{
	private GameController gameController;

	private Vector3 bannerSpawnPoint;

	private float[] precisionRanges = new float[5]
	{
		0f,
		0.25f,
		0.6f,
		0.9f,
		1f
	};

	private void Awake()
	{
		gameController = GetComponent<GameController>();
		CalculateBannerSpawnPoint();
	}

	private void CalculateBannerSpawnPoint()
	{
		float orthographicSize = Camera.main.orthographicSize;
		float y = orthographicSize - 2.4f;
		bannerSpawnPoint = new Vector3(0f, y, 0f);
	}

	public void SpawnBanner(float score)
	{
		int num = FindPrecisionIdForScore(score) + 1;
		string path = "Prefabs/PrecisionBanners/PrecisionBanner_" + num;
		GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load(path), bannerSpawnPoint, default(Quaternion)) as GameObject;
		StartCoroutine(ShowBanner(gameObject.GetComponent<PrecisionBannerAnimator>()));
		gameController.AddScoreToStars(num);
	}

	private IEnumerator ShowBanner(PrecisionBannerAnimator bannerAnimator)
	{
		yield return new WaitForSeconds(0.25f);
		bannerAnimator.AnimateBannerShow();
		yield return new WaitForSeconds(0.7f);
		bannerAnimator.AnimateBannerHide();
	}

	private int FindPrecisionIdForScore(float score)
	{
		for (int i = 0; i < precisionRanges.Length; i++)
		{
			if (score <= precisionRanges[i])
			{
				return i;
			}
		}
		return 0;
	}
}
